package theOrbalEra.common.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import theOrbalEra.client.ClientProxy;
import theOrbalEra.common.TheOrbalEra;
import theOrbalEra.common.network.PacketPlayerDataSave;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class OrbalUtils {
	
	public static void log(String str){
		System.out.println(str);
	}

	public static void addName(Object self, String Commonname, String chinese) {
		LanguageRegistry.addName(self, Commonname);
		LanguageRegistry.instance().addNameForObject(self, "zh_CN", chinese);
	}

	public static int[] openneeded(int slot) {
		int[] needed = { 20 * slot, 20 * slot, 20 * slot, 20 * slot, 20 * slot, 20 * slot, 20 * slot };
		return needed;
	}
	
public static void deStack(int fire, int water, int earth, int wind,int time,int space,int unreal, String username) {
		
		MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
		EntityPlayerMP player = server.getConfigurationManager().getPlayerForUsername(username);
		ItemStack[] main=player.inventory.mainInventory;
		for(int i=0;i<player.inventory.mainInventory.length;i++){
			
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.fireElementId+256){
					int paySize=main[i].stackSize;
					if(fire-paySize>=0){
						fire-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=fire;
						fire=0;
					}
						
				}
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.waterElementId+256){
					int paySize=main[i].stackSize;
					if(water-paySize>=0){
						water-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=water;
						water=0;
					}
						
				}
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.earthElementId+256){
					int paySize=main[i].stackSize;
					if(earth-paySize>=0){
						earth-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=earth;
						earth=0;
					}
						
				}
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.windElementId+256){
					int paySize=main[i].stackSize;
					if(wind-paySize>=0){
						wind-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=wind;
						wind=0;
					}
						
				}
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.timeElementId+256){
					int paySize=main[i].stackSize;
					if(time-paySize>=0){
						time-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=time;
						time=0;
					}
						
				}
			
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.spaceElementId+256){
					int paySize=main[i].stackSize;
					if(space-paySize>=0){
						space-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=space;
						space=0;
					}
						
				}
			
				if(main[i]!=null&&main[i].itemID==TheOrbalEra.unrealElementId+256){
					int paySize=main[i].stackSize;
					if(unreal-paySize>=0){
						unreal-=paySize;
						player.inventory.mainInventory[i]=null;
						
					}
					else{
						player.inventory.mainInventory[i].stackSize-=unreal;
						unreal=0;
					}
						
				}
			
			
			}
		
	if(fire==0&&water==0&&earth==0&&wind==0&&time==0&&space==0&&unreal==0)
		return;
	else	
		OrbalUtils.deStack(fire, water, earth, wind,time,space,unreal,username);
	
		
		
}
	


	public static int fromLoopIdGetEle(int loopId) {
		int eleId = 0;
		switch (loopId) {
		case Quartz.Attack1:
		case Quartz.Attack2:
		case Quartz.Attack3:
		case Quartz.BladeOfSealSkills:
		case Quartz.BladeOfChaos:
		case Quartz.BladeOfMaxKills:
			eleId= Element.Fire;
			break;
		case Quartz.HP1:
		case Quartz.HP2:
		case Quartz.HP3:
		case Quartz.Mind1:
		case Quartz.Mind2:
		case Quartz.Mind3:
		case Quartz.Heal:
		case Quartz.BladeOfFreeze:
			eleId= Element.Water;
			break;
		case Quartz.Defense1:
		case Quartz.Defense2:
		case Quartz.Defense3:
		case Quartz.BladeOfPoison:
		case Quartz.Bladeofpetrifaction:
		case Quartz.BladeOfSealMagic:
			eleId= Element.Earth;
			break;
		case Quartz.Avoid1:
		case Quartz.Avoid2:
		case Quartz.Avoid3:
		case Quartz.MagicDefense1:
		case Quartz.MagicDefense2:
		case Quartz.MagicDefense3:
		case Quartz.Prejudice1:
		case Quartz.Prejudice2:
		case Quartz.Prejudice3:
		case Quartz.Attracting:
			eleId= Element.Wind;
			break;
		case Quartz.BladeOfDie1:
		case Quartz.BladeOfDie2:
		case Quartz.Action1:
		case Quartz.Action2:
		case Quartz.Action3:
		case Quartz.Drive1:
		case Quartz.Drive2:
		case Quartz.BladeOfDark:
			eleId= Element.Time;
			break;
		case Quartz.Area:
		case Quartz.Speed1:
		case Quartz.Speed2:
		case Quartz.Speed3:
		case Quartz.EconEP1:
		case Quartz.EconEP2:
		case Quartz.EconEP3:
		case Quartz.EagleEye:
			eleId= Element.Space;
			break;
		case Quartz.Over:
		case Quartz.EP1:
		case Quartz.EP2:
		case Quartz.EP3:
		case Quartz.Hit1:
		case Quartz.Hit2:
		case Quartz.Hit3:
		case Quartz.SunShines:
		case Quartz.Invisible:
		case Quartz.Intelligence:
			eleId= Element.Unreal;
			break;
		}
		return eleId;
	}

	@SideOnly(Side.CLIENT)
	public static boolean isClientHost() {
		if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
			String name = ClientProxy.getPlayer().username;
			if (PacketPlayerDataSave.isRemote
					&& PacketPlayerDataSave.typeOfServer == 1) {
				MinecraftServer server = FMLClientHandler.instance()
						.getServer();
				if (server.getServerOwner().equals(name)) {
					return true;
				}
			}
		}
		return false;
	}

	@SideOnly(Side.CLIENT)
	public static String getPlayerName() {
		return ClientProxy.getPlayer().username;
	}

	public static int[] calculateOrbal1(int[] quartz) {
		int[] value1 = { 0, 0, 0, 0, 0, 0, 0 };
		int[] fir = new int[4];
		fir[0] = quartz[0];
		fir[1] = quartz[1];
		fir[2] = quartz[2];
		fir[3] = quartz[3];
		for (int i = 0; i < fir.length; i++) {
			switch (fir[i]) {
			case Quartz.HP1:
			case Quartz.Mind1:
				value1[Element.Water] += 1;
				break;
			case Quartz.HP2:
			case Quartz.Mind2:
			case Quartz.BladeOfFreeze:
				value1[Element.Water] += 3;
				break;
			case Quartz.HP3:
			case Quartz.Mind3:
				value1[Element.Water] += 5;
				break;
			case Quartz.EP1:
				value1[Element.Unreal] += 2;
				value1[Element.Space] += 1;
				value1[Element.Time] += 1;
				break;
			case Quartz.EP2:
				value1[Element.Unreal] += 3;
				value1[Element.Space] += 2;
				value1[Element.Time] += 2;
				break;
			case Quartz.EP3:
				value1[Element.Unreal] += 5;
				value1[Element.Space] += 3;
				value1[Element.Time] += 3;
				break;
			case Quartz.Heal:
				value1[Element.Water] += 3;
				value1[Element.Time] += 2;
				break;
			case Quartz.Attack1:
				value1[Element.Fire] += 1;
				break;
			case Quartz.Attack2:
			case Quartz.BladeOfSealSkills:
			case Quartz.BladeOfChaos:
			case Quartz.BladeOfMaxKills:
				value1[Element.Fire] += 3;
				break;
			case Quartz.Attack3:
				value1[Element.Fire] += 5;
				break;
			case Quartz.Defense1:
				value1[Element.Earth] += 1;
				break;
			case Quartz.Defense2:
			case Quartz.BladeOfPoison:
			case Quartz.Bladeofpetrifaction:
			case Quartz.BladeOfSealMagic:
				value1[Element.Earth] += 3;
				break;
			case Quartz.Defense3:
				value1[Element.Earth] += 5;
				break;
			case Quartz.Area:
			case Quartz.Speed2:
				value1[Element.Space] += 3;
				break;
			case Quartz.EagleEye:
				value1[Element.Space] += 3;
				value1[Element.Unreal] += 2;
				break;
			case Quartz.Speed1:
				value1[Element.Space] += 1;
				break;
			case Quartz.Speed3:
				value1[Element.Space] += 5;
				break;
			case Quartz.EconEP1:
				value1[Element.Space] += 2;
				value1[Element.Time] += 1;
				value1[Element.Unreal] += 1;
				break;
			case Quartz.EconEP2:
				value1[Element.Space] += 3;
				value1[Element.Time] += 2;
				value1[Element.Unreal] += 2;
				break;
			case Quartz.EconEP3:
				value1[Element.Space] += 5;
				value1[Element.Time] += 3;
				value1[Element.Unreal] += 3;
				break;
			case Quartz.Avoid1:
			case Quartz.MagicDefense1:
			case Quartz.Prejudice1:
				value1[Element.Wind] += 1;
				break;
			case Quartz.Avoid2:
			case Quartz.MagicDefense2:
			case Quartz.Prejudice2:
			case Quartz.Attracting:
				value1[Element.Wind] += 3;
				break;
			case Quartz.Avoid3:
			case Quartz.MagicDefense3:
			case Quartz.Prejudice3:
				value1[Element.Wind] += 5;
				break;
			case Quartz.Over:
				value1[Element.Unreal] += 3;
				break;
			case Quartz.BladeOfDie2:
				value1[Element.Time] += 0;
				break;
			case Quartz.Action1:
			case Quartz.Drive1:
				value1[Element.Time] += 1;
				break;
			case Quartz.BladeOfDie1:
			case Quartz.Action2:
			case Quartz.Drive2:
			case Quartz.BladeOfDark:
				value1[Element.Time] += 3;
				break;
			case Quartz.Action3:
				value1[Element.Time] += 5;
				break;
			case Quartz.Hit1:
				value1[Element.Unreal] += 1;
				break;
			case Quartz.Hit2:
				value1[Element.Unreal] += 3;
				break;
			case Quartz.SunShines:
				value1[Element.Fire] += 2;
				value1[Element.Unreal] += 3;
				break;
			case Quartz.Invisible:
				value1[Element.Earth] += 2;
				value1[Element.Unreal] += 3;
				break;
			case Quartz.Intelligence:
				value1[Element.Unreal] += 2;
				break;
			}
		}

		return value1;
	}

	public static int[] calculateOrbal2(int[] quartz) {
		int[] value2 = { 0, 0, 0, 0, 0, 0, 0 };
		int[] sec = new int[3];
		sec[0] = quartz[0];
		sec[1] = quartz[4];
		sec[2] = quartz[5];
		for (int i = 0; i < sec.length; i++) {
			switch (sec[i]) {
			case Quartz.HP1:
			case Quartz.Mind1:
				value2[Element.Water] += 1;
				break;
			case Quartz.HP2:
			case Quartz.Mind2:
			case Quartz.BladeOfFreeze:
				value2[Element.Water] += 3;
				break;
			case Quartz.HP3:
			case Quartz.Mind3:
				value2[Element.Water] += 5;
				break;
			case Quartz.EP1:
				value2[Element.Unreal] += 2;
				value2[Element.Space] += 1;
				value2[Element.Time] += 1;
				break;
			case Quartz.EP2:
				value2[Element.Unreal] += 3;
				value2[Element.Space] += 2;
				value2[Element.Time] += 2;
				break;
			case Quartz.EP3:
				value2[Element.Unreal] += 5;
				value2[Element.Space] += 3;
				value2[Element.Time] += 3;
				break;
			case Quartz.Heal:
				value2[Element.Water] += 3;
				value2[Element.Time] += 2;
				break;
			case Quartz.Attack1:
				value2[Element.Fire] += 1;
				break;
			case Quartz.Attack2:
			case Quartz.BladeOfSealSkills:
			case Quartz.BladeOfChaos:
			case Quartz.BladeOfMaxKills:
				value2[Element.Fire] += 3;
				break;
			case Quartz.Attack3:
				value2[Element.Fire] += 5;
				break;
			case Quartz.Defense1:
				value2[Element.Earth] += 1;
				break;
			case Quartz.Defense2:
			case Quartz.BladeOfPoison:
			case Quartz.Bladeofpetrifaction:
			case Quartz.BladeOfSealMagic:
				value2[Element.Earth] += 3;
				break;
			case Quartz.Defense3:
				value2[Element.Earth] += 5;
				break;
			case Quartz.Area:
			case Quartz.Speed2:
				value2[Element.Space] += 3;
				break;
			case Quartz.EagleEye:
				value2[Element.Space] += 3;
				value2[Element.Unreal] += 2;
				break;
			case Quartz.Speed1:
				value2[Element.Space] += 1;
				break;
			case Quartz.Speed3:
				value2[Element.Space] += 5;
				break;
			case Quartz.EconEP1:
				value2[Element.Space] += 2;
				value2[Element.Time] += 1;
				value2[Element.Unreal] += 1;
				break;
			case Quartz.EconEP2:
				value2[Element.Space] += 3;
				value2[Element.Time] += 2;
				value2[Element.Unreal] += 2;
				break;
			case Quartz.EconEP3:
				value2[Element.Space] += 5;
				value2[Element.Time] += 3;
				value2[Element.Unreal] += 3;
				break;
			case Quartz.Avoid1:
			case Quartz.MagicDefense1:
			case Quartz.Prejudice1:
				value2[Element.Wind] += 1;
				break;
			case Quartz.Avoid2:
			case Quartz.MagicDefense2:
			case Quartz.Prejudice2:
			case Quartz.Attracting:
				value2[Element.Wind] += 3;
				break;
			case Quartz.Avoid3:
			case Quartz.MagicDefense3:
			case Quartz.Prejudice3:
				value2[Element.Wind] += 5;
				break;
			case Quartz.Over:
				value2[Element.Unreal] += 3;
				break;
			case Quartz.BladeOfDie2:
				value2[Element.Time] += 0;
				break;
			case Quartz.Action1:
			case Quartz.Drive1:
				value2[Element.Time] += 1;
				break;
			case Quartz.BladeOfDie1:
			case Quartz.Action2:
			case Quartz.Drive2:
			case Quartz.BladeOfDark:
				value2[Element.Time] += 3;
				break;
			case Quartz.Action3:
				value2[Element.Time] += 5;
				break;
			case Quartz.Hit1:
				value2[Element.Unreal] += 1;
				break;
			case Quartz.Hit2:
				value2[Element.Unreal] += 3;
				break;
			case Quartz.SunShines:
				value2[Element.Fire] += 2;
				value2[Element.Unreal] += 3;
				break;
			case Quartz.Invisible:
				value2[Element.Earth] += 2;
				value2[Element.Unreal] += 3;
				break;
			case Quartz.Intelligence:
				value2[Element.Unreal] += 2;
				break;
			}
		}

		return value2;
	}

	public static int[] getOrbalArts(int[] value1, int[] value2) {
		int[] magic = { -1, -1, -1, -1, -1, -1, -1 };
		int i = 0;
		if (i < 7 && (value1[Element.Fire] >= 1 || value2[Element.Fire] >= 1)) {
			magic[i] = OrbalArtsIdList.FireBolt;
			i++;
		}
		if (i < 7 && (value1[Element.Fire] >= 3 || value2[Element.Fire] >= 3)) {
			magic[i] = OrbalArtsIdList.FlameArrow;
			i++;
		}
		if (i < 7 && (value1[Element.Fire] >= 6 || value2[Element.Fire] >= 6)) {
			magic[i] = OrbalArtsIdList.NapalmBreath;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Fire] >= 3 && value1[Element.Wind] >= 1 && value1[Element.Space] >= 1) || (value2[Element.Fire] >= 3
						&& value2[Element.Wind] >= 1 && value2[Element.Space] >= 1))) {
			magic[i] = OrbalArtsIdList.FireBoltEX;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Fire] >= 5 && value1[Element.Wind] >= 2 && value1[Element.Space] >= 2) || (value2[Element.Fire] >= 5
						&& value2[Element.Wind] >= 2 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.SpiralFlare;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Fire] >= 8 && value1[Element.Earth] >= 4 && value1[Element.Space] >= 2) || (value2[Element.Fire] >= 8
						&& value2[Element.Earth] >= 4 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.VolcanicRave;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Fire] >= 4 && value1[Element.Wind] >= 3
						&& value1[Element.Space] >= 2 && value1[Element.Unreal] >= 1) || (value2[Element.Fire] >= 4
						&& value2[Element.Wind] >= 3
						&& value2[Element.Space] >= 2 && value2[Element.Unreal] >= 1))) {
			magic[i] = OrbalArtsIdList.Forte;
			i++;
		}
		if (i < 7 && (value1[Element.Water] >= 1 || value2[Element.Water] >= 1)) {
			magic[i] = OrbalArtsIdList.AquaBleed;
			i++;
		}
		if (i < 7 && (value1[Element.Water] >= 5 || value2[Element.Water] >= 5)) {
			magic[i] = OrbalArtsIdList.BlueImpact;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 4 && value1[Element.Wind] >= 2 && value1[Element.Space] >= 1) || (value2[Element.Water] >= 4
						&& value2[Element.Wind] >= 2 && value2[Element.Space] >= 1))) {
			magic[i] = OrbalArtsIdList.DiamondDust;
			i++;
		}
		if (i < 7 && (value1[Element.Water] >= 1 || value2[Element.Water] >= 1)) {
			magic[i] = OrbalArtsIdList.Tear;
			i++;
		}
		if (i < 7 && (value1[Element.Water] >= 4 || value2[Element.Water] >= 4)) {
			magic[i] = OrbalArtsIdList.Teara;
			i++;
		}
		if (i < 7 && (value1[Element.Water] >= 6 || value2[Element.Water] >= 6)) {
			magic[i] = OrbalArtsIdList.Tearal;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 2 && value1[Element.Space] >= 1) || (value2[Element.Water] >= 2 && value2[Element.Space] >= 1))) {
			magic[i] = OrbalArtsIdList.LaTear;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 5 && value1[Element.Space] >= 2) || (value2[Element.Water] >= 5 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.LaTeara;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 4 && value1[Element.Unreal] >= 2) || (value2[Element.Water] >= 4 && value2[Element.Unreal] >= 2))) {
			magic[i] = OrbalArtsIdList.Curia;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 8 && value1[Element.Unreal] >= 4 && value1[Element.Space] >= 2) || (value2[Element.Water] >= 8
						&& value2[Element.Unreal] >= 4 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.LaCuria;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Water] >= 4 && value1[Element.Earth] >= 2 && value1[Element.Unreal] >= 1) || (value2[Element.Water] >= 4
						&& value2[Element.Earth] >= 2 && value2[Element.Unreal] >= 1))) {
			magic[i] = OrbalArtsIdList.Revive;
			i++;
		}
		if (i < 7 && (value1[Element.Earth] >= 1 || value2[Element.Earth] >= 1)) {
			magic[i] = OrbalArtsIdList.StoneHammer;
			i++;
		}
		if (i < 7 && (value1[Element.Earth] >= 5 || value2[Element.Earth] >= 5)) {
			magic[i] = OrbalArtsIdList.EarthLance;
			i++;
		}
		if (i < 7 && (value1[Element.Earth] >= 3 || value2[Element.Earth] >= 3)) {
			magic[i] = OrbalArtsIdList.PetrifyBreath;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Earth] >= 3 && value1[Element.Space] >= 2) || (value2[Element.Earth] >= 3 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.StoneImpact;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Earth] >= 8 && value1[Element.Space] >= 4) || (value2[Element.Earth] >= 8 && value2[Element.Space] >= 4))) {
			magic[i] = OrbalArtsIdList.TitanicRoar;
			i++;
		}
		if (i < 7 && (value1[Element.Earth] >= 2 || value2[Element.Earth] >= 2)) {
			magic[i] = OrbalArtsIdList.EarthGuard;
			i++;
		}
		if (i < 7 && (value1[Element.Earth] >= 4 || value2[Element.Earth] >= 4)) {
			magic[i] = OrbalArtsIdList.EarthWall;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Earth] >= 4 && value1[Element.Water] >= 3
						&& value1[Element.Space] >= 2 && value1[Element.Unreal] >= 1) || (value2[Element.Earth] >= 4
						&& value2[Element.Water] >= 3
						&& value2[Element.Space] >= 2 && value2[Element.Unreal] >= 1))) {
			magic[i] = OrbalArtsIdList.Crest;
			i++;
		}
		if (i < 7 && (value1[Element.Wind] >= 1 || value2[Element.Wind] >= 1)) {
			magic[i] = OrbalArtsIdList.AirStrike;
			i++;
		}
		if (i < 7 && (value1[Element.Wind] >= 4 || value2[Element.Wind] >= 4)) {
			magic[i] = OrbalArtsIdList.Aerial;
			i++;
		}
		if (i < 7 && (value1[Element.Wind] >= 8 || value2[Element.Wind] >= 8)) {
			magic[i] = OrbalArtsIdList.AeroStorm;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Wind] >= 4 && value1[Element.Space] >= 2) || (value2[Element.Wind] >= 4 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.Lightning;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Wind] >= 8 && value1[Element.Space] >= 4) || (value2[Element.Wind] >= 8 && value2[Element.Space] >= 4))) {
			magic[i] = OrbalArtsIdList.PlasmaWave;
			i++;
		}
		if (i < 7 && (value1[Element.Wind] >= 2 || value2[Element.Wind] >= 2)) {
			magic[i] = OrbalArtsIdList.SylphenGuard;
			i++;
		}
		if (i < 7 && (value1[Element.Wind] >= 6 || value2[Element.Wind] >= 6)) {
			magic[i] = OrbalArtsIdList.SylphenWing;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 1 || value2[Element.Time] >= 1)) {
			magic[i] = OrbalArtsIdList.SoulBlur;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 5 || value2[Element.Time] >= 5)) {
			magic[i] = OrbalArtsIdList.ShadowSpear;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Time] >= 4 && value1[Element.Space] >= 2 && value1[Element.Unreal] >= 1) || (value2[Element.Time] >= 4
						&& value2[Element.Space] >= 2 && value2[Element.Unreal] >= 1))) {
			magic[i] = OrbalArtsIdList.HellGate;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Time] >= 8 && value1[Element.Space] >= 4 && value1[Element.Unreal] >= 2) || (value2[Element.Time] >= 8
						&& value2[Element.Space] >= 4 && value2[Element.Unreal] >= 2))) {
			magic[i] = OrbalArtsIdList.WhiteGehenna;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 1 || value2[Element.Time] >= 1)) {
			magic[i] = OrbalArtsIdList.ClockUp;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 9 || value2[Element.Time] >= 9)) {
			magic[i] = OrbalArtsIdList.ClockUpEX;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 3 || value2[Element.Time] >= 3)) {
			magic[i] = OrbalArtsIdList.AntiSept;
			i++;
		}
		if (i < 7 && (value1[Element.Time] >= 11 || value2[Element.Time] >= 11)) {
			magic[i] = OrbalArtsIdList.AntiSeptAll;
			i++;
		}
		if (i < 7
				&& (value1[Element.Unreal] >= 5 || value2[Element.Unreal] >= 5)) {
			magic[i] = OrbalArtsIdList.ChaosBrand;
			i++;
		}
		if (i < 7
				&& ((value1[Element.Unreal] >= 4 && value1[Element.Earth] >= 3
						&& value1[Element.Fire] >= 3
						&& value1[Element.Water] >= 2
						&& value1[Element.Wind] >= 2 
						&& value1[Element.Space] >= 2) 
						|| (value2[Element.Unreal] >= 4
						&& value2[Element.Earth] >= 3
						&& value2[Element.Fire] >= 3
						&& value2[Element.Water] >= 2
						&& value2[Element.Wind] >= 2 && value2[Element.Space] >= 2))) {
			magic[i] = OrbalArtsIdList.Saint;
			i++;
		}

		return magic;
	}

	public static IconsIndex getOrbalArtsIndex(int orbalArtsId) {
		IconsIndex iconsIndex = null;
		if (orbalArtsId == -1)
			iconsIndex=new IconsIndex(16 * 15, 16 * 15);
		if (orbalArtsId < 16)
			iconsIndex= new IconsIndex(0 + orbalArtsId * 16, 0);
		if (orbalArtsId >= 16 && orbalArtsId < 32)
			iconsIndex= new IconsIndex(0 + (orbalArtsId - 16) * 16, 16);
		if (orbalArtsId >= 32 && orbalArtsId < 48)
			iconsIndex= new IconsIndex(0 + (orbalArtsId - 32) * 16, 32);
		return iconsIndex;

	}

	public static List<Integer> canExchange(List<Integer> canExchange,
			int[] have, boolean[] use) {
		int fire = 0;
		int water = 0;
		int earth = 0;
		int wind = 0;
		int time = 0;
		int space = 0;
		int unreal = 0;
		if (use[0])
			fire = have[0];
		if (use[1])
			water = have[1];
		if (use[2])
			earth = have[2];
		if (use[3])
			wind = have[3];
		if (use[4])
			time = have[4];
		if (use[5])
			space = have[5];
		if (use[6])
			unreal = have[6];
		// fire
		if (fire >= 20)
			canExchange.add(Quartz.Attack1);
		if (fire >= 200)
			canExchange.add(Quartz.Attack2);
		if (fire >= 800)
			canExchange.add(Quartz.Attack3);
		if (fire >= 50) {
			canExchange.add(Quartz.BladeOfSealSkills);
			canExchange.add(Quartz.BladeOfChaos);
			canExchange.add(Quartz.BladeOfMaxKills);
		}
		// water
		if (water >= 20)
			canExchange.add(Quartz.HP1);
		if (water >= 200)
			canExchange.add(Quartz.HP2);
		if (water >= 800)
			canExchange.add(Quartz.HP3);
		if (water >= 30)
			canExchange.add(Quartz.Mind1);
		if (water >= 300)
			canExchange.add(Quartz.Mind2);
		if (water >= 900)
			canExchange.add(Quartz.Mind3);
		if (water >= 200 && time >= 50)
			canExchange.add(Quartz.Heal);
		if (water >= 50 && time >= 50)
			canExchange.add(Quartz.BladeOfFreeze);

		// earth
		if (earth >= 20)
			canExchange.add(Quartz.Defense1);
		if (earth >= 200)
			canExchange.add(Quartz.Defense2);
		if (earth >= 800)
			canExchange.add(Quartz.Defense3);
		if (earth >= 50) {
			canExchange.add(Quartz.BladeOfPoison);
			canExchange.add(Quartz.Bladeofpetrifaction);
			canExchange.add(Quartz.BladeOfSealMagic);
		}
		// wind
		if (wind >= 20) {
			canExchange.add(Quartz.Avoid1);
			canExchange.add(Quartz.MagicDefense1);
			canExchange.add(Quartz.Prejudice1);
		}
		if (wind >= 200) {
			canExchange.add(Quartz.Avoid2);
			canExchange.add(Quartz.MagicDefense2);
			canExchange.add(Quartz.Prejudice2);
		}
		if (wind >= 800) {
			canExchange.add(Quartz.Avoid3);
			canExchange.add(Quartz.MagicDefense3);
			canExchange.add(Quartz.Prejudice3);
		}
		if (wind >= 100 && water >= 30) {
			canExchange.add(Quartz.Attracting);
		}
		// time
		if (time >= 100)
			canExchange.add(Quartz.BladeOfDie1);
		if (time >= 150)
			canExchange.add(Quartz.BladeOfDie2);
		if (time >= 20) {
			canExchange.add(Quartz.Action1);
		}
		if (time >= 200) {
			canExchange.add(Quartz.Action2);
			canExchange.add(Quartz.Drive1);
		}
		if (time >= 800) {
			canExchange.add(Quartz.Action3);
			canExchange.add(Quartz.Drive2);
		}
		if (time >= 50) {
			canExchange.add(Quartz.BladeOfDark);
		}
		// space
		if (space >= 50)
			canExchange.add(Quartz.Area);
		if (space >= 100)
			canExchange.add(Quartz.Speed1);
		if (space >= 200)
			canExchange.add(Quartz.Speed2);
		if (space >= 800)
			canExchange.add(Quartz.Speed3);
		if (space >= 10 && time >= 20 && unreal >= 10)
			canExchange.add(Quartz.EconEP1);
		if (space >= 100 && time >= 200 && unreal >= 100)
			canExchange.add(Quartz.EconEP2);
		if (space >= 800 && time >= 1000 && unreal >= 800)
			canExchange.add(Quartz.EconEP3);
		if (space >= 100 && time >= 20 && wind >= 20)
			canExchange.add(Quartz.EagleEye);

		// unreal
		if (unreal >= 100)
			canExchange.add(Quartz.Over);
		if (time >= 10 && space >= 10 && unreal >= 30)
			canExchange.add(Quartz.EP1);
		if (time >= 100 && space >= 100 && unreal >= 200)
			canExchange.add(Quartz.EP2);
		if (time >= 500 && space >= 500 && unreal >= 800)
			canExchange.add(Quartz.EP3);
		if (earth >= 20 && time >= 10 && space >= 10 && unreal >= 30)
			canExchange.add(Quartz.Hit1);
		if (earth >= 100 && time >= 100 && space >= 100 && unreal >= 200)
			canExchange.add(Quartz.Hit2);
		if (earth >= 400 && time >= 500 && space >= 500 && unreal >= 800)
			canExchange.add(Quartz.Hit3);
		if (fire >= 30 && wind >= 30)
			canExchange.add(Quartz.SunShines);
		if (time >= 200 && space >= 200 && unreal >= 200)
			canExchange.add(Quartz.Invisible);
		if (wind >= 20 && time >= 300 && space >= 300 && unreal >= 300)
			canExchange.add(Quartz.Intelligence);
		return canExchange;
	}

	public static List findTarget(World world,AxisAlignedBB aabb,EntityPlayer player){
		List<Entity> entity=new ArrayList<>();
		List<Entity> willRemove=new ArrayList<>();
		entity=world.getEntitiesWithinAABBExcludingEntity(player, aabb);
		Iterator<Entity> iterator = entity.iterator();
		while(iterator.hasNext()){
			Entity temp=iterator.next();
			if(!(temp instanceof EntityLiving))
				willRemove.add(temp);
		}
		entity.removeAll(willRemove);
		return entity;
		
	}
	public static int isPositive(double Coord){
		return Coord>=0?1:-1;
	}
	

}
